package beans;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.io.StreamCorruptedException;


import ourImage.OurPlanarImage;
import pimpmypipe.interfaces.IOable;

/**
 * Basis Bean für alle Beans(inklusive Sink und Source)
 * 
 * @author marcel meraner
 */
public abstract class BaseBean extends Canvas implements
		IOable<OurPlanarImage, OurPlanarImage> {

	private static final long serialVersionUID = 1L;
	private final static int BEAN_WIDTH = 100;
	private final static int BEAN_HEIGHT = 30;
	private Color inActiveColor;
	private Color activeColor;

	public BaseBean() {
		setSize(BEAN_WIDTH, BEAN_HEIGHT);
		inActiveColor = new Color(30, 30, 30);
		activeColor = new Color(30, 150, 30);
	}

	@Override
	public abstract OurPlanarImage read() throws StreamCorruptedException;

	@Override
	public abstract void write(OurPlanarImage value)
			throws StreamCorruptedException;

	/**
	 * Retuniert den Namen der aktuellen Bean
	 * 
	 * @return
	 */
	public abstract String getFilterName();

	/**
	 * Retuniert true wenn die Bean aktiv ist
	 * 
	 * @return
	 */
	public abstract boolean isFilterEnabled();

	@Override
	public void paint(Graphics g) {
		String name = getFilterName();
		g.drawString(name, 5, 20);

		Color c;
		if (isFilterEnabled()) {
			c = activeColor;
		} else {
			c = inActiveColor;
		}
		g.setColor(c);
		g.drawRect(0, 0, BEAN_WIDTH - 1, BEAN_HEIGHT - 1);
		g.drawRect(1, 1, BEAN_WIDTH - 3, BEAN_HEIGHT - 3);
	}

}
